﻿///***************************************************************
/// 시  스  템 : Updms.Fit
/// 단위시스템 : FIT
/// 계      층 : Presentation Layer
/// 프로그램명 : Fit3011p
/// 파  일  명 : Fit3011p.aspx.cs
/// 설      명 : 월별운동수행결과 팝업
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2014-06-19 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Web;

using SMFramework.Configuration;
using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.Dac;
using Base.AppFramework;
using Base.AppFramework.Web.UI.CommandBar;

using Updms.Fit.Exe;
using System.Web.UI.WebControls;

namespace Updms.Fit
{
	public partial class Fit3012p : Updms.Common.BaseClass.PageBase
	{
		#region 콘트롤

		public static readonly string PID = "Fit3012p";
		Global global = new Global();

		private string kw1 = ""; //년월
		private string kw2 = ""; //운동부위
		private string kw3 = ""; //운동명

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				OnPageLoad();
				if (CheckViewAuth())
				{
					SelectProcess();
				}
			}
		}

		//OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region CheckViewAuth

		//인증검사
		private bool CheckViewAuth()
		{
			using (AccessCheck access = new AccessCheck())
			{
				//접근권한 체크
				if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
				{
					Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					return false;
				}
				return true;
			}
		}

		#endregion

		#region SetInit

		// SetInit
		private void SetInit()
		{
			if (Request.QueryString["kw1"] != null)
			{
				kw1 = Server.UrlDecode(Request.QueryString["kw1"].ToString().Trim());
			}

			if (Request.QueryString["kw2"] != null)
			{
				kw2 = Server.UrlDecode(Request.QueryString["kw2"].ToString().Trim());
			}

			if (Request.QueryString["kw3"] != null)
			{
				kw3 = Server.UrlDecode(Request.QueryString["kw3"].ToString().Trim());
			}
		}

		#endregion

		#region SelectProcess

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_base_ym", typeof(int), kw1);
			lo_dp.AddProperty("ls_training_part", typeof(int), kw2);
			lo_dp.AddProperty("ls_training_type_id", typeof(int), kw3);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Fit3012p_NT _Fit3012p_NT = new Fit3012p_NT())
			{
				lo_ds.Merge(_Fit3012p_NT.GetMonthlyTotalResultByTrainingPartNType(lo_dp));
			}

			GridView1.DataSource = lo_ds;
			GridView1.DataBind();
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				string view_order = gv.DataKeys[e.Row.RowIndex].Values["View_Order"].ToString();
				string training_id = gv.DataKeys[e.Row.RowIndex].Values["Training_Id"].ToString();

				//운동명 소계
				if (view_order.Contains("X"))
				{
					e.Row.Attributes.Add("class", "sub_total_v1");
					//소계 colspan
					e.Row.Cells[4].ColumnSpan = 2;
					e.Row.Cells[5].Visible = false;
				}

				switch (view_order)
				{
					case "BA001": //소계
						e.Row.Attributes.Add("class", "total_v2");
						//소계 colspan
						e.Row.Cells[2].ColumnSpan = 3;
						e.Row.Cells[3].Visible = false;
						e.Row.Cells[4].Visible = false;
						e.Row.Cells[5].Visible = false;
						break;
					case "BA002": //총계
						e.Row.Attributes.Add("class", "total_v3");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_tb_dbl");
						}
						//총계 colspan
						e.Row.Cells[1].ColumnSpan = 4;
						e.Row.Cells[2].Visible = false;
						e.Row.Cells[3].Visible = false;
						e.Row.Cells[4].Visible = false;
						e.Row.Cells[5].Visible = false;
						break;
					default:
						e.Row.Cells[4].Text = "<a href=\"#\" onclick=\"goWeightTrainingResultPage('" + training_id + "');\">" + e.Row.Cells[4].Text + "</a>";
						break;
				}
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			sGv.RowSpanGridView(GridView1, 1); //Training_Part_Nm
			sGv.RowSpanGridView(GridView1, 2); //Training_Nm
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			ChangePageMode();
		}

		//ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region 버튼이벤트

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_base_ym", typeof(int), kw1);
			lo_dp.AddProperty("ls_training_part", typeof(int), kw2);
			lo_dp.AddProperty("ls_training_type_id", typeof(int), kw3);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Fit3012p_NT _Fit3012p_NT = new Fit3012p_NT())
			{
				lo_ds.Merge(_Fit3012p_NT.GetMonthlyTotalResultByTrainingPartNType(lo_dp));
			}

			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		#endregion

	}
}